import {request ,request1 }from "@/utils/request.js";
/**
 * 词汇包列表
 * 
*/
export function getDrawList(params)
{
  return request.post("getDrawList", params);
}
export function getUserBookList(params)
{
  return request.post("getUserBookList", params);
}
export function getWordList(params)
{
  return request.post("getWordList", params);
}
export function getWordInfo(params)
{
  return request.post("getWordInfo", params);
}
export function addStudyWord(params)
{
  return request.post("addStudyWord", params);
}
export function getStudyWordList(params)
{
  return request.post("getStudyWordList", params);
}
export function addStudyLog(params)
{
  return request.post("addStudyLog", params);
}
export function editNewWord(params)
{
  return request.post("editNewWord", params);
}
export function getNewWordList(params)
{
  return request.post("getNewWordList", params);
}
export function getExamList(params)
{
  return request.post("getExamList", params);
}
export function getVideoList(params)
{
  return request.post("getVideoList", params);
}
export function addGold(params)
{
  return request.post("addGold", params);
}
export function getUserList(params)
{
  return request.post("getUserList", params);
}
export function aiOCR(params)
{
  return request.post("aiOCR", params);
}
export function addNewWordBook(params)
{
  return request.post("addNewWordBook", params);
}
export function editNewWordBook(params)
{
  return request.post("editNewWordBook", params);
}
export function deleteNewWordBook(params)
{
  return request.post("deleteNewWordBook", params);
}
export function getStudyLogList(params)
{
  return request.post("getStudyLogList", params);
}
/**
 * 获取登录授权login
 * 
*/
export function login(params)
{
  return request.post('login', params);
}
export function resetPwd(params)
{
  return request.post('resetPwd', params);
}
export function register(params)
{
  return request.post('register', params);
}
export function deleteUser(params)
{
  return request.post('deleteUser', params);
}

// 格式化日期时间
export function formatTime(date) {
  var year = date.getFullYear();
  var month = date.getMonth() + 1; // 月份从0开始，需要加1
  var day = date.getDate();
  var hour = date.getHours();
  var minute = date.getMinutes();
  var second = date.getSeconds();
  return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
}

// 格式化日期
export function formatDate(date) {
  var year = date.getFullYear();
  var month = date.getMonth() + 1; // 月份从0开始，需要加1
  var day = date.getDate();
  return year + '-' + month + '-' + day;
}

// 播放音乐
export function playMusic(filename, callback, bLoop, isBg) {
	const innerAudioContext = uni.createInnerAudioContext({useWebAudioImplement: true});
	innerAudioContext.autoplay = true;
	innerAudioContext.src = filename;
	if( isBg){
		innerAudioContext.volume = 0.2;
	}
	if(bLoop){
		innerAudioContext.loop = true;
	}
	innerAudioContext.onPlay(() => {
		//console.log('开始播放');
		callback && callback(true);
	});
	innerAudioContext.onError((err) => {
		console.error('播放音乐出错:', err);
		callback && callback(false);
	});
	innerAudioContext.onEnded(() => {
		//console.log('播放结束');
		innerAudioContext.destroy()
		callback && callback(false);
	});
	return innerAudioContext;
}